using Godot;

public abstract partial class BaseSkill : SkillModel
{
    [Signal]
    public delegate void OnCastStartEventHandler(SkillEventEntity e);
    [Signal]
    public delegate void OnCastEndEventHandler(SkillEventEntity e);

    public int CurrentCoolDown { get; protected set; }
    public virtual void Cast(SkillEventEntity e = null)
    {
        CurrentCoolDown = Cooldown;
        if (Cost.ContainsKey(SkillCostType.Health))
        {
            OwnerRobot.Entity.CurrentHealth -= Cost[SkillCostType.Health].As<int>();
        }
        else if (Cost.ContainsKey(SkillCostType.Sprite))
        {
            OwnerRobot.Entity.CurrentSprite -= Cost[SkillCostType.Sprite].As<int>();
        }
        EmitSignal(SignalName.OnCastStart, e);
    }
    public virtual bool TryCast()
    {
        if (CurrentCoolDown > 0) return false;
        if (OwnerRobot == null) return false;
        if (OwnerRobot.IsActionEnd) return false;
        if (OwnerRobot.IsDeath) return false;
        if (Cost.ContainsKey(SkillCostType.Health))
        {
            if (OwnerRobot.Entity.CurrentHealth < Cost[SkillCostType.Health].As<int>())
            {
                return false;
            }
        }
        else if (Cost.ContainsKey(SkillCostType.Sprite))
        {
            if (OwnerRobot.Entity.CurrentSprite < Cost[SkillCostType.Sprite].As<int>())
            {
                return false;
            }
        }
        return true;
    }
    public Robot OwnerRobot { get; set; }

    public void CastStart(SkillEventEntity e)
    {
        EmitSignal(SignalName.OnCastStart, e);
    }
    public void CastEnd(SkillEventEntity e)
    {
        EmitSignal(SignalName.OnCastEnd, e);
    }
}